package com.qmerak.common;

/**
 * 日期工具
 * 
 */
public class BSCalendarHelper {

	/**
	 * 根据日期产生日期对象，日期格式 yyyymm
	 */
	public static BSCalendar newBSCalendar(String date) {
		BSCalendar c = BSCalendar.now();
		String year = date.substring(0, 4);
		String month = date.substring(4, 6);
		c.setYear(Integer.parseInt(year));
		c.setDay(1);
		c.setMonth(Integer.parseInt(month));
		return c;
	}

	/**
	 * 得到两个日期的相差月数
	 */
	public static int getDispersionOfMonths(String lateMonth, String beforeMonth) {
		BSCalendar lateM = newBSCalendar(lateMonth);
		BSCalendar beforeM = newBSCalendar(beforeMonth);
		return lateM.getMonthDispersion(beforeM);
	}

	/**
	 * 得到两个日期的相差年数
	 */
	public static int getDispersionOfYears(String late, String before) {
		BSCalendar lateM = newBSCalendar(late);
		BSCalendar beforeM = newBSCalendar(before);
		return lateM.getYearDispersion(beforeM);
	}

	/**
	 * 得到两个日期的相差天数
	 */
	public static int getDispersionOfDays(String last, String before) {
		BSCalendar lateM = newBSCalendar(last);
		BSCalendar beforeM = newBSCalendar(before);
		return lateM.getDayDispersion(beforeM);
	}

}
